import Wx from "../utils/Wx";
import CustomError from "../utils/CustomError";
module.exports = {
    /*
    * 获取小程序码
    * */
    getUnlimitedCode: async function (path) {
        try {
            let res = await Wx.cloudFunction("open", {
                actionName: "getUnlimitedCode",
                path: path
            })
            return await Wx.writeFile(res.buffer);
        } catch (e) {
            throw new CustomError(e, "Open.getUnlimitedCode").parse()
        }
    },

    /*
    * 解析小程序码
    * */
    getQueryCodeOptions: async function (md5) {
        try {
            return await Wx.cloudFunction("open", {
                actionName: "getQueryCodeOptions",
                md5: md5
            })
        } catch (e) {
            throw new CustomError(e, "Open.getQueryCodeOptions").parse()
        }
    },

    /*
    * 发送模板消息
    * */
    sendMessage: async function (params) {
        try {
            return await Wx.cloudFunction("open", Object.assign({actionName: "sendMessage"}, params))
        } catch (e) {
            throw new CustomError(e, "Open.getQueryCodeOptions").parse()
        }
    },
}